//
//  CourseCenterListCell.m
//  xpkc
//
//  Created by TopSageOSX on 14/12/19.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "CourseCenterListCell.h"
#import <UIImageView+AFNetworking.h>
@implementation CourseCenterListCell

- (void)awakeFromNib {
   
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatCoursesListCell];
    }
    return self;
}
- (void)creatCoursesListCell{
    //创建
    self.courseImg = [[UIImageView alloc]init];
    self.courseTitle = [[UILabel alloc]init];
    self.courseTeacher = [[UILabel alloc]init];
    self.courseGood = [[UILabel alloc]init];
    self.courseComment = [[UILabel alloc]init];
    self.coursePrice = [[UILabel alloc]init];
    self.courseClass = [[UILabel alloc]init];
    UIImageView *teacherImg = [[UIImageView alloc]init];
    UIImageView *goodImg = [[UIImageView alloc]init];
    UIImageView *commentImg = [[UIImageView alloc]init];
    
    //位置
    CGFloat offwidth = 0.04*SCREEN_WIDTH;
    CGFloat viewwidth = SCREEN_WIDTH/2-offwidth-offwidth/2;
    CGFloat imgheight = viewwidth *9/16;
    CGRect Img_img_frame;
    CGRect title_label_frame;
    CGRect teacher_img_frame,teacher_label_frame;
    CGRect good_img_frame,good_label_frame;
    CGRect comment_img_frame,comment_label_frame;
    CGRect price_label_frame;
    CGRect class_label_frame;
    
    Img_img_frame       = CGRectMake(offwidth, offwidth, viewwidth, imgheight);
    title_label_frame   = CGRectMake(offwidth, offwidth + imgheight, viewwidth, offwidth);
    teacher_img_frame   = CGRectMake(offwidth, offwidth + imgheight + offwidth, offwidth, offwidth);
    teacher_label_frame = CGRectMake(offwidth + offwidth, offwidth + imgheight + offwidth, 50, offwidth);
    good_img_frame      = CGRectMake(offwidth+viewwidth-offwidth*6, offwidth + imgheight + offwidth, offwidth, offwidth);
    good_label_frame    = CGRectMake(offwidth+viewwidth-offwidth*5, offwidth + imgheight + offwidth, offwidth*2, offwidth);
    comment_img_frame   = CGRectMake(offwidth+viewwidth-offwidth*3, offwidth + imgheight + offwidth, offwidth, offwidth);
    comment_label_frame = CGRectMake(offwidth+viewwidth-offwidth*2, offwidth + imgheight + offwidth, offwidth*2, offwidth);
    price_label_frame = CGRectMake(offwidth+viewwidth-offwidth*3, offwidth+imgheight-offwidth, offwidth*3, offwidth);
    class_label_frame = CGRectMake(offwidth, offwidth+imgheight+offwidth, offwidth*6, offwidth);
    
    self.courseImg.frame = Img_img_frame;
    self.courseTitle.frame = title_label_frame;
    teacherImg.frame = teacher_img_frame;
    self.courseTeacher.frame = teacher_label_frame;
    goodImg.frame = good_img_frame;
    self.courseGood.frame = good_label_frame;
    commentImg.frame = comment_img_frame;
    self.courseComment.frame = comment_label_frame;
    self.coursePrice.frame = price_label_frame;
    self.courseClass.frame = class_label_frame;
 
    
   
    
    //可变字体
    UIFont *tempfont = FONT_SYS(0.8*offwidth);
    
    self.courseTitle.font = tempfont;
    self.courseTeacher.font = tempfont;
    self.courseGood.font = tempfont;
    self.courseComment.font = tempfont;
    self.coursePrice.font = tempfont;
    self.courseClass.font = tempfont;
    
    self.courseTitle.textColor = [UIColor lightGrayColor];
    self.courseTeacher.textColor = [UIColor lightGrayColor];
    self.courseGood.textColor = [UIColor lightGrayColor];
    self.courseComment.textColor = [UIColor lightGrayColor];
    self.coursePrice.textColor = [UIColor whiteColor];
    self.courseClass.textColor = [UIColor lightGrayColor];
    
//    self.courseTitle.text = @"2015 职称英语 综合 全程班";
//    self.courseTeacher.text = @"王霞";
//    self.courseGood.text = @"1000";
//    self.courseComment.text = @"56";
//    self.coursePrice.text = @"￥:1000";
    
    self.coursePrice.backgroundColor = [UIColor redColor];
    
    
    teacherImg.image = [UIImage imageNamed:@"Img_teacher"];
    goodImg.image = [UIImage imageNamed:@"Img_good"];
    commentImg.image = [UIImage imageNamed:@"Img_comment"];
    
    //添加
    [self addSubview:self.courseImg];
    [self addSubview:self.courseTitle];
//    [self addSubview:teacherImg];
//    [self addSubview:self.courseTeacher];
//    [self addSubview:goodImg];
//    [self addSubview:self.courseGood];
//    [self addSubview:commentImg];
//    [self addSubview:self.courseComment];
    [self addSubview:self.coursePrice];
    [self addSubview:self.courseClass];
}

- (void)setValueWithDic:(NSDictionary *)dic{
    NSString *name = [dic objectForKey:@"name"];
    NSString *class = [dic valueForKey:@"class_name"];
    NSString *subject = [dic valueForKey:@"subject_name"];
    
    NSArray *array = [name componentsSeparatedByString:@" "];
    self.courseTitle.text = [NSString stringWithFormat:@"%@ %@",[array firstObject],class];
    self.courseClass.text = [NSString stringWithFormat:@"%@",subject];
    self.coursePrice.text = [NSString stringWithFormat:@"￥ %d",[[dic objectForKey:@"trueprice"]intValue]];
    self.courseaid = [dic objectForKey:@"aid"];
    [self.courseImg setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"litpic"]] placeholderImage:[UIImage imageNamed:@""]];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
